﻿namespace BlamanticUI.Components;

/// <summary>
/// Render a segment of item in <see cref="Tab"/> component.
/// </summary>
[CssClass("tab")]
public class TabItem : BlazorChildComponentBase<Tab, TabItem>, IHasOnActive,IHasChildContent
{
    /// <summary>
    /// Gets or sets the title.
    /// </summary>
    [Parameter]
    public string Title { get; set; }
    /// <summary>
    /// Perform an action when tab item is actived.
    /// </summary>
    [Parameter]public EventCallback<bool> OnActive { get; set; }
    /// <summary>
    /// Determined a state of component can be actived.
    /// </summary>
    [Parameter] public bool Active { get; set; }
    /// <summary>
    /// A segment of UI content to render.
    /// </summary>
    [Parameter]public RenderFragment? ChildContent { get; set; }

    /// <summary>
    /// Renders the component to the supplied <see cref="T:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder" />.
    /// </summary>
    /// <param name="builder">A <see cref="T:Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder" /> that will receive the render output.</param>
    protected override void BuildRenderTree(RenderTreeBuilder builder)
    {
        builder.CreateComponent<Segment>(0, ChildContent, new
        {
            Attached = true,
            AttachedVertical = ParentComponent.VerticalPosition == VerticalPosition.Top ? VerticalPosition.Bottom : VerticalPosition.Top,
            AdditionalCssClass = GetCssClassString()
        });

        //builder.OpenComponent<Segment>(0);
        //builder.AddAttribute(1, nameof(Segment.Attached), true);
        //builder.AddAttribute(2, nameof(Segment.AttachedVertical), ParentComponent.VerticalPosition == VerticalPosition.Top ? VerticalPosition.Bottom : VerticalPosition.Top);

        //builder.AddAttribute(6, nameof(Segment.AdditionalCssClass), GetCssClassString());
        //builder.AddAttribute(10, nameof(Segment.ChildContent), ChildContent);
        //builder.CloseComponent();
    }
}
